perf(moe): add frozen grouped GEMM for adapter training - #3
Merged
Conversation
…ding Re-entrant activation checkpointing only attaches a grad_fn when some tensor input requires grad. Under adapter-only training the embedding is frozen, so every checkpointed chunk output carried no grad_fn and the adapters inside the chunks received no gradient. Detach and re-enable grad on the block input before the chunk loop. The rest of the source commits added a MambaStack checkpointed forward, which upstream has since absorbed: MambaStack moved to megatron/core/models/hybrid/hybrid_block.py and routes full-granularity recompute through megatron/core/recompute.py::checkpointed_forward. Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit 91c8b41) (cherry picked from commit abd235c) (cherry picked from commit 8d9ad06) Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
taufeeque9
marked this pull request as ready for review
August 26, 2026 03:49
SamAdamDay
approved these changes
Aug 28, 2026
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Collaborator
Author
|
Codex-authored final B200 validation update: Merged Core
The earlier targeted pytest job |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written by Codex.
Why this change
Nemotron-3 Super LoRA freezes the 128 local expert base weights. On B200, the pinned Transformer Engine grouped path launched roughly one small GEMM per expert, leaving substantial launch overhead. The opt-in
torchbackend packs the frozen expert weights once and runs the base branch throughtorch.nn.functional.grouped_mmwhen available, withtorch._grouped_mmas the compatibility fallback. The ordinary Bridge LoRA branch remains unchanged.This path reduced the measured logprob-plus-update cycle from 21.640 s to 14.684 s on the production-shaped benchmark: 32.1% less time and 47.4% more throughput, with the same peak allocated memory.
B200 throughput evidence
The comparison used the same node, step-75 checkpoint, fixed production-mixed token batch, and TP4/PP1/EP4/ETP1 topology. Both arms used BF16 LoRA, ordinary all-to-all dispatch, a 32k dynamic token cap, and 121,088 input tokens per iteration.
Artifacts:
102251,tf-super-deepep-ab-v1-a4e9b214c0/super-topology-benchmark.json,tp4-alltoallarm.102265,tf-super-torch-gmm-v1-a518a324d7/super-topology-benchmark.json.102277,tf-super-torch-gmm-profile-v1-a518a324d7.The parity gate reported zero relative-L2 and max-absolute error for both forward output and input gradient, including experts with zero assigned tokens. The runtime packed 80 grouped FC1/FC2 modules and relocated 52.5 GiB of frozen weights without adding checkpoint entries.
Why existing behavior remains safe
transformer_engineremains the default. No model uses the new path unless its config explicitly selectsmoe_expert_gemm_backend="torch".Parameterobjects and state-dict keys are preserved. Each expert parameter becomes a view into one non-persistent contiguous buffer.Full-recompute correctness
The PR also carries the small frozen-input guard needed by PP1 adapter-only full recompute. Re-entrant checkpointing otherwise sees a frozen embedding output with
requires_grad=Falseand can detach every checkpointed chunk from the adapters inside it.The regression freezes the block and input, installs trainable low-rank adapters, runs backward, and requires nonzero gradients on every adapter parameter. It covers uniform recompute and block recompute; the block case exercises both a checkpointed layer and the uncheckpointed remainder. The production 32k and 48k NeMo-RL runs use this full-recompute path; their recorded gradients are nonzero and their losses move.
Scope deliberately omitted
expert_fc1_actrecompute was faster than whole-MoE recompute at short context, but the 32k selective arm OOMed because it did not cover the 40 Mamba mixers. The tested 32k and 48k recipes use full recompute instead.Validation status
git diff --checkpass at final headc03fbc4a1.fork-basecheck passes, every PR commit carries DCO sign-off, Sam's review is approved, and all five follow-up review threads are addressed and resolved.8447c0d3.8447c0d3is provided by NeMo-RL job113785: it used the torch backend, PP1 full recompute, and ordinary LoRA, migrated the step-75 adapter checkpoint, and completed optimizer steps with nonzero gradient norms and changing rewards in W&B runas6tqeze.c03fbc4a1adds review hardening around unsupported configuration combinations, public/private API selection, malformed split validation, and broader regression coverage. A separate one-B200 targeted run, job170738, is queued against that exact commit; it does not replace or share GPUs with the production run.Commit signing
All commits carry DCO sign-off. Cryptographic signing was unavailable because this machine has no configured GPG or SSH signing identity.